package main

import (
	"blog/api"
	"fmt"
	"lib/server/web"
)

func main() {
	httpServer := web.NewWebServer()

	initRoute(httpServer)

	httpServer.RegisterOnShutdown(onShutdownCallback)

	if err := httpServer.Start(); err != nil {
		panic(err)
	}
}

func initRoute(server *web.WebServer) {
	server.AddLogic("/client", api.ClientApiInstance)

	server.Get("/", func(ctx *web.Context) {
		ctx.OutputJson(map[string]interface{}{
			"ID": 1,
		})
	})
}

func onShutdownCallback() {
	// deregister consul
	fmt.Println("before server shutdown")
}
